<template>
  <!-- 图片数量1张 -->
  <div
    class="single"
    v-if="post.cover.length === 1"
    @click="$router.push({ path: `/article/${post.id}` })"
  >
    <div class="left">
      <p class="title">{{ post.title }}</p>
      <p class="info">
        <span>{{ post.nickname }}</span>
      </p>
    </div>
    <van-image :src="post.cover[0]" width="110" height="75" fit="contain" />
  </div>
  <!-- 图片多余一张 -->
  <div
    class="single3"
    v-else-if="post.cover.length >= 2"
    @click="$router.push({ path: `/article/${post.id}` })"
  >
    <p class="title">{{ post.title }}</p>
    <div class="imgs">
      <van-image
        :src="item"
        width="110"
        height="75"
        fit="contain"
        v-for="(item, index) in post.cover"
        :key="index"
      />
    </div>
    <p class="info">
      <span>{{ post.nickname }}</span>
    </p>
  </div>
  <!-- 没有图片 -->
  <div
    class="single4"
    v-else-if="post.cover.length === 0"
    @click="$router.push({ path: `/article/${post.id}` })"
  >
    <p class="title">{{ post.title }}</p>
    <p class="author">
      {{ post.nickname }}
    </p>
  </div>
</template>

<script>
import axios from "@/utils/myaxios.js";
export default {
  props: {
    post: {
      type: Object,
      required: true,
    },
  },
  data() {
    return {
      url: axios.defaults.baseURL,
    };
  },
};
</script>

<style lang='less' scoped>
body {
  overflow-x: hidden;
  overflow-y: hidden;
}
.author {
  line-height: 24px;
  font-size: 12px;
  padding-left: 5px;
  color: @secondaryTextColor;
  > span:nth-of-type(1) {
    padding-right: 15px;
  }
}
.info {
  font-size: 12px;
  padding-left: 5px;
  padding-top: 5px;
  color: @secondaryTextColor;
  > span:nth-of-type(1) {
    padding-right: 15px;
  }
}
.title {
  font-size: 18px;
  color: @primaryTextColor;
  padding: 0px 5px;
  line-height: 24px;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  text-overflow: ellipsis;
}

.single {
  padding: 12px;
  box-sizing: border-box;
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid #ccc;
  flex-wrap: wrap;
  background-color: #fff;
  .left {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    overflow: hidden;
  }
}

.single3 {
  padding: 12px;
  border-bottom: 1px solid #ccc;
  background-color: #fff;
  .imgs {
    display: flex;
    padding-top: 5px;
    justify-content: space-evenly;
  }
}

.single4 {
  padding: 12px;
  box-sizing: border-box;
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid #ccc;
  flex-wrap: wrap;
  background-color: #fff;

  .left {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    overflow: hidden;
  }
}
</style>
